<?php

namespace app\common\validate;

use app\common\validate\Base;

class Mail extends Base
{

    protected $rule = [
        'target|收件人' => 'require|checkTarget',
        'title|邮件标题' => 'require|min:2',
        'content|邮件内容' => 'require|min:2',
        'captcha|验证码'=>'require|captcha'
    ];

    protected $message = [

    ];

    protected $scene = [
        // 前台发送邮件
        'home_send' => ['target','title','content','captcha'],
    ];

    protected function checkTarget($v,$rule,$data){
        $memberModel = new \app\common\model\Member;
        if(!$memberModel->where(['mid'=>$v])->find()){
            $this->message['target.checkTarget'] = '收件人不存在';
            return false;
        }else{
            return true;
        }
    }

}